package com.myjoje.config.support;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class DaoSupport {

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    /**
     * 保存
     */
    public int save(String statement, Object parameter) {

        return sqlSessionTemplate.insert(statement, parameter);
    }


    /**
     * 更新
     */
    public int update(String statement, Object parameter) {

        return sqlSessionTemplate.update(statement, parameter);
    }

    /**
     * 删除
     */
    public int delete(String statement, Object parameter) {

        return sqlSessionTemplate.delete(statement, parameter);
    }

    /**
     * 查找返回一个对象
     */
    public Map selectForMap(String statement, Object parameter) {
        return sqlSessionTemplate.selectOne(statement, parameter);
    }

    public Object selectForObject(String statement, Object parameter) {
        return sqlSessionTemplate.selectOne(statement, parameter);
    }

    /**
     * 查找返回集合
     */
    public List selectForList(String statement, Object parameter) {

        return sqlSessionTemplate.selectList(statement, parameter);
    }
}
